package repo

import (
	"gorm.io/gorm"
	"sensi/app/model"
)

type Weather struct {
}

func (Weather) Hourly(db *gorm.DB, city, hour string) (*model.WeatherHourly, error) {
	hourly := &model.WeatherHourly{}
	err := db.Where("city = ? and in_hour = ?", city, hour).First(hourly).Error
	if err == gorm.ErrRecordNotFound {
		return nil, nil
	}
	return hourly, err
}

func (Weather) Daily(db *gorm.DB, city, date string) (*model.WeatherDaily, error) {
	daily := &model.WeatherDaily{}
	err := db.Where("city = ? and in_day = ?", city, date).First(daily).Error
	if err == gorm.ErrRecordNotFound {
		return nil, nil
	}
	return daily, err
}
